package org.easy.core.util;

import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.stream.Collectors;


public class Sets {
    @SafeVarargs
    public static <T> HashSet<T> newHashSet(T... elements) {
        if (elements == null) {
            return null;
        } else {
            HashSet<T> set = newHashSet();
            Collections.addAll(set, elements);
            return set;
        }
    }

    @SafeVarargs
    public static <T> Set<T> set(T... elements) {
        if (elements == null) {
            return null;
        } else {
            HashSet<T> set = newHashSet();
            Collections.addAll(set, elements);
            return set;
        }
    }

    public static <T> HashSet<T> newHashSet(Iterable<? extends T> elements) {
        return elements == null ? null : (HashSet) Streams.stream(elements).collect(Collectors.toCollection(HashSet::new));
    }

    public static <T> HashSet<T> newHashSet(Iterator<? extends T> elements) {
        return elements == null ? null : (HashSet) Streams.stream(elements).collect(Collectors.toCollection(HashSet::new));
    }

    public static <T> HashSet<T> newHashSet() {
        return new HashSet();
    }

    public static <T> Set<T> emptySet() {
        return Collections.emptySet();
    }

    private Sets() {
    }
}
